/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.andersen.web.service;

import com.andersen.database.dao.EmployeeDao;
import com.andersen.database.dao.OfficeDao;
import com.andersen.database.entity.OfficeEntity;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Corvus 11
 */
@Service
public class OfficeDetailsService {
    
    private static final Logger LOG = Logger.getLogger(CustomUserDetailsService.class);
	
    @Autowired
	private OfficeDao officeDao;

    @Autowired
    private EmployeeDao employeeDao;
        
    //private List<OfficeEntity> officeListCache = null;
    //private boolean officeListChanged = false;

    public List<OfficeEntity> getOfficeList() {
        //  if (officeListCache == null || officeListChanged) {
        //      if (officeListChanged) officeListCache.clear();
        //      officeListCache = dao.getAllObjects();
        //  }
        //  List<OfficeEntity> result = new ArrayList<OfficeEntity>(officeListCache);
        return officeDao.getAllObjects();
    }

    // Получаем ФИО менеджера по id
    public String getFIOManager(long id){
        return employeeDao.getFIOManager(id);
    }

    // Добавляем офис
    public void addOffice(String name,String location,String address,long managerId){
        officeDao.addOffice(name,location,address,managerId);
    }

    // Получаем id менеджера по id офиса
    public long getIdManager(long idOffice){
        return officeDao.getIdManager(idOffice);
    }

    // Редактируем информацию об офисе
    public void editOffice(long id,String newName,String newLocation,String newAddress,long newManagerId){
        officeDao.editOffice(id,newName,newLocation,newAddress,newManagerId);
    }

    // Удаляем офис
    public void removeOffice(long id){
        officeDao.removeOffice(id);
    }
}
